<!DOCTYPE html>
<html>
<head>
    <include file="Include:meta"/>
    <title>运营项目列表-目的地运营集团数据管理平台</title>
    <include file="Include:style"/>
    <style>
        .background {
            background: #f5f5f5;
        }
    </style>
</head>
<body>
<include file="Include:header"/>
<include file="Include:left"/>
<div id="main">
    <div class="crumbs">
        <div class="crumbs-text">运营项目列表</div>
        <if condition="(is_permission('CRMX-M',NULL,1) or is_permission('CRMX-M',NULL,6))">
            <div class="right">
                <a href="__APP__/CrmProjects/add" class="btn left mr5">添加项目</a>
            </div>
        </if>
    </div>
    <div id="content">
        <div class="table-scrollx">
            <table class="table table-bordered">
                <tr class="table-header fixed-table-header">
                    <td width="418">
                        <select name="project_id" class="form-control w400">
                            <option value=""
                            <if condition="$project_id eq null"> selected</if>
                            >项目编号-项目名称</option>
                            <foreach name="res_projects_all" item="vo">
                                <option value="{$vo['project_id']}"
                                <if condition="$project_id eq $vo['project_id']"> selected</if>
                                >{$vo['project_num']}-{$vo['project_name']}</option>
                            </foreach>
                        </select>
                    </td>
                    <td width="100">
                        <select name="leader" class="form-control w100">
                            <option value=""
                            <if condition="$leader eq null"> selected</if>
                            >负责人</option>
                            <foreach name="leader_array" item="vo">
                                <option value="{$vo}"
                                <if condition="$leader eq $vo"> selected</if>
                                >{:get_userName($vo)}</option>
                            </foreach>
                        </select>
                    </td>
                    <td width="">项目群负责人</td>
                    <td width="">项目启动日期</td>
                    <td width="100">
                        <select name="stage" id="jieduan" class="form-control w100">
                            <option value=""
                            <if condition="$stage eq null"> selected</if>
                            >状态</option>
                            <for start="1" end="7">
                                <option value="{$i}"
                                <if condition="$stage eq $i"> selected</if>
                                >{:get_projects_stage($i)}</option>
                            </for>
                        </select>
                    </td>
                    <td width="">操作</td>
                </tr>
                <if condition="$result eq NULL">
                    <tr>
                        <td class="text-center" colspan="11">暂无相关内容</td>
                    </tr>
                </if>
                <foreach name="result" item="vo">
                    <tr>
                        <td><a href="__APP__/CrmProjects/detail/project_id/{$vo['project_id']}">{$vo['project_num']}-{$vo['project_name']}</a></td>
                        <td>{:get_userName($vo['leader'])}</td>
                        <td>{:get_userName($vo['group_leader'])}</td>
                        <td>{$vo['start_date']}</td>
                        <td><a href="javascript:;" class="stage" project_id="{$vo['project_id']}"
                               project_name="{$vo['project_name']}" project_stage="{$vo['stage']}"
                               project_stage_name="{:get_projects_stage($vo['stage'])}">{:get_projects_stage($vo['stage'])}</a>
                        </td>
                        <!--<td>{:get_projects_stage($vo['stage'])}</td>-->
                        <td class="nowrap">
                            <if condition="(get_permission('CRMX-M',NULL,1) or get_permission('CRMX-M',NULL,2)or (get_permission('CRMX-M',NULL,3) and $vo['add_uid'] eq $login_id) or (get_permission('CRMX-M',NULL,7) and $vo['add_uid'] eq $login_id))">
                                <a href="__APP__/CrmProjects/edit/project_id/{$vo['project_id']}" data-toggle="tooltip"
                                   data-placement="left"
                                   title="" class="mr5"
                                   data-original-title="编辑"><i class="glyphicon glyphicon-edit">编辑</i></a>
                            </if>
                        </td>
                    </tr>
                </foreach>
                </if>
            </table>
        </div>
        <div class="pages">{$page}</div>
    </div>
</div>
<!--对话框-->
<div class="modal fade" id="stage_modal" style="margin-top: 8%">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4>变更项目阶段</h4>
                <i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
            </div>
            <div class="modal-body">
                <table class="table table-bordered">
                    <input name="projects_id" value="" hidden>
                    <tr>
                        <td width="100" class="text-right"><strong><span class="asterisk">*</span>项目名称</strong></td>
                        <td>
                            <input id="project_name" class="form-control w200" value="" readonly="">
                        </td>
                    </tr>
                    <tr>
                        <td width="100" class="text-right"><strong><span class="asterisk">*</span>项目阶段</strong></td>
                        <td id="stage">
                            <select name="stage" class="form-control w200 required_select">

                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td width="100" class="text-right"><strong><span class="asterisk">*</span>变更时间</strong></td>
                        <td>
                            <input type="text" name="change_date" class="form-control Wdate w100 required-text"
                                   value="{$today}" onclick="WdatePicker()" readonly="" autocomplete="off">
                        </td>
                    </tr>
                    <tr>
                        <td width="100" class="text-right"><strong><span class="asterisk">*</span>变更人</strong></td>
                        <td>
                            <select name="change_uid" class="form-control w200 required_select" autocomplete="off"
                                    required>
                                <option value="{:$_SESSION['dms_uid']}">{:$_SESSION['dms_username']}</option>
                                <foreach name="user_list" item="vo">
                                    <option value="{$vo.id}">{$vo.username}</option>
                                </foreach>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td width="100" class="text-right"><strong><span class="asterisk">*</span>原因</strong></td>
                        <td>
                            <textarea name="remark" class="form-control w300" autocomplete="off"></textarea>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn hr_sub">确认</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<select id="select_id" hidden>
    <option value="">请选择</option>
    <for start="1" end="7">
        <option value="{$i}">{:get_projects_stage($i)}</option>
    </for>
</select>
<include file="Include:javascript"/>
<script type="text/javascript">
    $(function () {
        $('.stage').click(function () {
            $('#stage_modal').show();
            var project_id = $(this).attr("project_id");
            var project_name = $(this).attr("project_name");
            var project_stage = $(this).attr("project_stage");
            if (project_stage == 1) {
                $("#select_id").find("option[value=1]").attr("selected",true);
                $("#select_id").find("option[value!=1]").attr("selected",false);
            }
            if (project_stage == 2) {
                $("#select_id").find("option[value=2]").attr("selected",true);
                $("#select_id").find("option[value!=2]").attr("selected",false);
            }
            if (project_stage == 3) {
                $("#select_id").find("option[value=3]").attr("selected",true);
                $("#select_id").find("option[value!=3]").attr("selected",false);
            }
            if (project_stage == 4) {
                $("#select_id").find("option[value=4]").attr("selected",true);
                $("#select_id").find("option[value!=4]").attr("selected",false);
            }
            if (project_stage == 5) {
                $("#select_id").find("option[value=5]").attr("selected",true);
                $("#select_id").find("option[value!=5]").attr("selected",false);
            }
            if (project_stage == 6) {
                $("#select_id").find("option[value=6]").attr("selected",true);
                $("#select_id").find("option[value!=6]").attr("selected",false);
            }
            $(document).on("change", "[name='stage']", function () {
                var val_stage = $(this).val();
                $("[name='stage']").val(val_stage);
            });
            var html = $("#select_id").html()
            $("[name='stage']").html(html).select2();
            $("[name='project_id']").val(project_id);
            $("[id='project_name']").val(project_name);
            $('#stage_modal').modal();
            $('#stage_modal .error-item').hide();
        })
        //确认操作
        $("#stage_modal").find(".hr_sub").on("click", function () {
            var tag = true,
                modal = $("#stage_modal");
            if (tag) {
                var project_id = $("[name='project_id']").val()
                var stage = $("[name='stage']").val()
                var change_date = $("[name='change_date']").val()
                var remark = $("[name='remark']").val()
                // $('.hr_sub').click(function () {
                $.ajax({
                    type: "POST",
                    asnyc: false,
                    dataType: "json",
                    data: {
                        "project_id": project_id,
                        "stage": stage,
                        "change_date": change_date,
                        "remark": remark
                    },
                    url: "__APP__/CrmProjects/projects_flow",
                    success: function (data) {
                        if (data.status) {
                            success_pop(data['status'], data['msg']);
                        } else {
                            defeated_alert(data.msg);
                            $('#stage_modal').hide();
                        }
                    }
                });
            }
        })
    })
    $(document).on("change", "[name='project_id']", function () {
        var val = $(this).val();
        window.location.href = "__APP__/CrmProjects/index/project_id/" + val;
    });
    $(document).on("change", "[name='leader']", function () {
        var val = $(this).val();
        window.location.href = "__APP__/CrmProjects/index/leader/" + val;
    });
    $(document).on("change", "[id='jieduan']", function () {
        var val = $(this).val();
        window.location.href = "__APP__/CrmProjects/index/stage/" + val;
    });

</script>
</body>
</html>